﻿/*
 * Copyright 2002-2010 Edward L. Stauff.                  Contact: <EdStauff@gmail.com>.
 * 
 * This file, "DateTimeParseException.cs", is part of the "Stauffware.Common" 
 * library.  "Stauffware.Common" is free software: you can redistribute it 
 * and/or  modify it under the terms of the GNU Lesser Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or (at your option) 
 * any later version.
 * 
 * "Stauffware.Common" is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Lesser Public License along with 
 * the "Stauffware.Common" sources.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Text;
using Stauffware.Common.Core;

namespace Stauffware.Common.Time
{
	/// <summary>
	/// Indicates a syntax error in a string containing a date and/or time.
	/// </summary>

	public class DateTimeParseException : Exception
	{
		/// <summary>
		/// A description of the error.
		/// </summary>
		public readonly string Description;

		/// <summary>
		/// The original input string.
		/// </summary>
		public readonly string Input;

		/// <summary>
		/// The offending input token, or null.
		/// </summary>
		public readonly string OffendingToken;

		/// <summary></summary>
		/// <param name="description"></param>
		public DateTimeParseException (string description)
			: base(description)
		{
			this.Description = description;
		}

		/// <summary></summary>
		/// <param name="input"></param>
		/// <param name="description"></param>
		public DateTimeParseException (string input, string description)
			: base(description)
		{
			this.Description = description;
			this.Input = input;
		}

		/// <summary></summary>
		/// <param name="input"></param>
		/// <param name="offendingToken"></param>
		/// <param name="description"></param>
		public DateTimeParseException (string input, string offendingToken, string description)
			: base(description + " (\"" + offendingToken + "\")")
		{
			this.Description = description;
			this.Input = input;
			this.OffendingToken = offendingToken;
		}

		/// <summary></summary>
		/// <param name="input"></param>
		/// <param name="offendingToken"></param>
		/// <param name="innerException"></param>
		/// <param name="description"></param>
		public DateTimeParseException (string input, string offendingToken,
							Exception innerException, string description)
			: base(description + " (\"" + offendingToken + "\")\r\n\"" + input + "\"", innerException)
		{
			this.Description = description;
			this.Input = input;
			this.OffendingToken = offendingToken;
		}

#if !SILVERLIGHT
		/// required for serialization
		protected DateTimeParseException (System.Runtime.Serialization.SerializationInfo info,
							System.Runtime.Serialization.StreamingContext context)
			: base(info, context) { }
#endif
	}
}
